package com.sharedmobility.model;

import java.math.BigDecimal;
import java.util.Date;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Vehicle {
    @Expose
    private Integer id;
    
    @Expose
    private String type;
    
    @Expose
    private String brand;
    
    @Expose
    private String model;
    
    @Expose
    @SerializedName("plateNumber")
    private String plateNumber;
    
    @Expose
    @SerializedName("pricePerMinute")
    private BigDecimal pricePerMinute;
    
    @Expose
    private Integer status; // 0: 可用, 1: 使用中, 2: 维修中
    
    // 经度
    @Expose
    private Double longitude;
    
    // 纬度
    @Expose
    private Double latitude;
    
    // 位置字符串（不序列化到JSON）
    private String location;
    
    private Integer batteryLevel;
    private Date lastMaintenance;

    // Getters and Setters
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public String getPlateNumber() {
        return plateNumber;
    }

    public void setPlateNumber(String plateNumber) {
        this.plateNumber = plateNumber;
    }

    public BigDecimal getPricePerMinute() {
        return pricePerMinute;
    }

    public void setPricePerMinute(BigDecimal pricePerMinute) {
        this.pricePerMinute = pricePerMinute;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getBatteryLevel() {
        return batteryLevel;
    }

    public void setBatteryLevel(Integer batteryLevel) {
        this.batteryLevel = batteryLevel;
    }

    public Date getLastMaintenance() {
        return lastMaintenance;
    }

    public void setLastMaintenance(Date lastMaintenance) {
        this.lastMaintenance = lastMaintenance;
    }

    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
        if (location != null && location.startsWith("POINT(")) {
            try {
                // 从POINT(x y)格式解析经纬度
                String pointStr = location.substring(6, location.length() - 1).trim();
                String[] coords = pointStr.split("\\s+");
                if (coords.length == 2) {
                    this.longitude = Double.parseDouble(coords[0]);
                    this.latitude = Double.parseDouble(coords[1]);
                    System.out.println("Successfully parsed location: " + location + 
                        " to longitude=" + this.longitude + ", latitude=" + this.latitude);
                } else {
                    System.err.println("Invalid coordinate format: " + location);
                }
            } catch (Exception e) {
                System.err.println("Error parsing location: " + location + " - " + e.getMessage());
                this.longitude = null;
                this.latitude = null;
            }
        } else if (location != null) {
            System.out.println("Location string is not in POINT format: " + location);
        }
    }

    // 获取格式化的位置字符串
    public String getFormattedLocation() {
        if (longitude != null && latitude != null) {
            return String.format("经度: %.6f, 纬度: %.6f", longitude, latitude);
        }
        return "位置未知";
    }
} 